package config_table

import (
	"base"
	"config/item"
)

type itemTable struct {
	Table map[base.AssetItemId]*config_item.Item
}
type itemConfig []*config_item.Item

var (
	Item itemTable
)

func init() {
	register(Item.parse, new(itemConfig), "item/item_config.json")
}

func (table *itemTable) parse(records interface{}) (err error) {
	temp := make(map[base.AssetItemId]*config_item.Item)
	for _, item := range *records.(*itemConfig) {
		temp[item.Id] = item
		if err = Asset.register(item.Id, base.AssetType(item.Type)); err != nil {
			return
		}
	}

	Item.Table = temp
	return
}
